<?php
class photo { 
    var $ph_id;
    var $ph_u_id;
    var $ph_desc;
    var $ph_img_route;
    var $ph_img_mini_route;
    var $ph_img_name;
    var $ph_date;
    var $ph_location;
    var $ph_status;


    function Delete(){
        
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $q = " select ph_status from photo where ph_id ='".$this->ph_id."' " ;
        $rse = $DB->ObtenerData($q);   
        
        if($rse[0]["ph_status"]==0){
            $this->ph_status = 1;
        }else{
            $this->ph_status = 0;
        }
        
        $query = " UPDATE estado SET
                     ph_status='".$this->ph_status."'
                     where ph_id ='".$this->ph_id."' " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from photo where ph_id ='".$this->ph_id."' ";
        $rs = $DB->ObtenerData($query, "photo" );

        $this->ph_id = $rs[0]["ph_id"];
        $this->ph_u_id = $rs[0]["ph_u_id"];
        $this->ph_desc = $rs[0]["ph_desc"];
        $this->ph_img_route = $rs[0]["ph_img_route"];
        $this->ph_img_mini_route = $rs[0]["ph_img_mini_route"];
        $this->ph_img_name = $rs[0]["ph_img_name"];
        $this->ph_date = $rs[0]["ph_date"];
        $this->ph_location = $rs[0]["ph_location"];
        $this->ph_status = $rs[0]["ph_status"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO photo (
                     ph_id, ph_u_id, ph_desc, ph_img_route, ph_img_mini_route, ph_img_name, ph_date, ph_location, ph_status)
                    VALUES (NULL, '$this->ph_u_id', '$this->ph_desc', '$this->ph_img_route', '$this->ph_img_mini_route', '$this->ph_img_name', '$this->ph_date', '$this->ph_location', '$this->ph_status');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "photo" ) { //modulo photo
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY ph_status desc, ph_desc asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and ph_status = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from photo where ph_desc like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from photo where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO PHOTO
            
             $query = " Select $vals from photo where ph_status = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "photo");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $p = new photo();
                $p->set_ph_id($val["ph_id"]);
                $p->set_ph_u_id($val["ph_u_id"]);
                $p->set_ph_desc($val["ph_desc"]);
                $p->set_ph_img_route($val["ph_img_route"]);
                $p->set_ph_img_mini_route($val["ph_img_mini_route"]);
                $p->set_ph_img_name($val["ph_img_name"]);
                $p->set_ph_date($val["ph_date"]);
                $p->set_ph_location($val["ph_location"]);
                $p->set_ph_status($val["ph_status"]);
                $rs2[] = $p;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value["ph_status"] == 1) {
                        $rs[$key]["ph_status"] = "<img src='images/png/estado_habilitado.png' />".$e[$value["ph_status"]];
                    } else {
                        $rs[$key]["ph_status"] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value["ph_status"]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_ph_id(){
        return $this->ph_id;
    }
    function set_ph_id($val){
        $this->ph_id = $val;
    }

    function get_ph_u_id(){
        return $this->ph_u_id;
    }
    function set_ph_u_id($val){
        $this->ph_u_id = $val;
    }

    function get_ph_desc(){
        return $this->ph_desc;
    }
    function set_ph_desc($val){
        $this->ph_desc = $val;
    }

    function get_ph_img_route(){
        return $this->ph_img_route;
    }
    function set_ph_img_route($val){
        $this->ph_img_route = $val;
    }

    function get_ph_img_mini_route(){
        return $this->ph_img_mini_route;
    }
    function set_ph_img_mini_route($val){
        $this->ph_img_mini_route = $val;
    }

    function get_ph_img_name(){
        return $this->ph_img_name;
    }
    function set_ph_img_name($val){
        $this->ph_img_name = $val;
    }

    function get_ph_date(){
        return $this->ph_date;
    }
    function set_ph_date($val){
        $this->ph_date = $val;
    }

    function get_ph_location(){
        return $this->ph_location;
    }
    function set_ph_location($val){
        $this->ph_location = $val;
    }

    function get_ph_status(){
        return $this->ph_status;
    }
    function set_ph_status($val){
        $this->ph_status = $val;
    }

}